package com.gf.controller.mnue;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gf.bean.Menu;
import com.gf.service.impl.MenuServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;


/*
 * 用来输出首页热门商品所需要的三个商品的数据的servlet
 * */

@WebServlet(name = "SelectthreemenuServlet",urlPatterns = "/threemenu")
public class SelectthreemenuServlet extends HttpServlet {
    static MenuServiceImpl menuimpl = null;
    static {
        menuimpl=new MenuServiceImpl();


    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Menu> selectthreemenu = menuimpl.selectthreemenu();
        //直接调用service服务层对象查询出所需要的数据

        PrintWriter out = response.getWriter();
        JSONObject backjson = new JSONObject();
        //新建json对象返回成功的响应码和提示信息
        backjson.put("status", 200);
        backjson.put("data", selectthreemenu);

        out.println(JSON.toJSON(backjson));
        out.flush();
        out.close();


    }
}
